<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button @click="myHandleAdd" type="primary" icon="plus">新增</a-button>
      <a-button type="primary" icon="download" @click="handleExportXls('项目运维表')">导出</a-button>
      <a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl" @change="handleImportExcel">
        <a-button type="primary" icon="import">导入</a-button>
      </a-upload>
      <!-- 高级查询区域 -->
      <j-super-query :fieldList="superFieldList" ref="superQueryModal" @handleSuperQuery="handleSuperQuery"></j-super-query>
      <!-- <a-button type="primary" icon="plus" @click="goToMaintenanceTemplateList()">运维内容</a-button> -->
      <a-dropdown v-if="selectedRowKeys.length > 0">
        <a-menu slot="overlay">
          <a-menu-item key="1" @click="batchDel"><a-icon type="delete"/>删除</a-menu-item>
        </a-menu>
        <a-button style="margin-left: 8px"> 批量操作 <a-icon type="down" /></a-button>
      </a-dropdown>
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
        <!-- <span style="float:right;">
          <a @click="loadData()"><a-icon type="sync" />刷新</a>
          <a-divider type="vertical" />
          <list-columns-fix-setter
            v-if="columns.length > 0"
            v-model="columns"
            :def-columns="columns"
            @change="columnChange"
          />
        </span> -->
      </div>

      <a-table
        ref="table"
        size="middle"
        :scroll="{x:true}"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        class="j-table-force-nowrap"
        @change="handleTableChange">

        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text,record">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" :preview="record.id" height="25px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="downloadFile(text)">
            下载
          </a-button>
        </template>

        <span slot="action" slot-scope="text, record">
          <a @click="myHandleEdit(record)">编辑</a>

          <a-divider type="vertical" />
          <a-dropdown>
            <a class="ant-dropdown-link">更多 <a-icon type="down" /></a>
            <a-menu slot="overlay">
              <a-menu-item>
                <a @click="handleDetail(record)">详情</a>
              </a-menu-item>
              <a-menu-item>
                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>

      </a-table>
    </div>

    <yks-equipment-devops-modal ref="modalForm" @ok="modalFormOk"></yks-equipment-devops-modal>
  </a-card>
</template>

<script>

  import '@/assets/less/TableExpand.less'
  import { httpAction, getAction } from '@/api/manage'
  import { mixinDevice } from '@/utils/mixin'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import YksEquipmentDevopsModal from './modules/YksEquipmentDevopsModal'
  import {filterMultiDictText} from '@/components/dict/JDictSelectUtil'
import YksMaintenanceTemplateListVue from './YksMaintenanceTemplateList.vue'

  export default {
    name: 'YksEquipmentDevopsList',
    mixins:[JeecgListMixin, mixinDevice],
    components: {
      YksEquipmentDevopsModal
    },
    data () {
      return {
        description: '项目运维表管理页面',
        // 表头
        columns: [
          {
            title: '#',
            dataIndex: '',
            key:'rowIndex',
            width:60,
            align:"center",
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
          },
          {
            title:'名称',
            align:"center",
            dataIndex: 'name'
          },
          {
            title:'项目',
            align:"center",
            dataIndex: 'equipmentId_dictText'
          },
          {
            title:'运维类型',
            align:"center",
            dataIndex: 'devopsPersontype_dictText'
          },
          {
            title:'运维人员',
            align:"center",
            dataIndex: 'maintenancePerson_dictText'
          },
          {
            title:'运维部门',
            align:"center",
            dataIndex: 'maintenanceDept_dictText'
          },
          {
            title:'触发类型',
            align:"center",
            dataIndex: 'triggerType_dictText'
          },
          {
            title:'初次触发时间',
            align:"center",
            dataIndex: 'triggerTime',
            customRender:function (text) {
              return !text?"":(text.length>10?text.substr(0,10):text)
            }
          },
          {
            title:'重复次数',
            align:"center",
            dataIndex: 'repeatNumber'
          },
          {
            title:'重复间隔',
            align:"center",
            dataIndex: 'repeatGap'
          },
          {
            title:'重复间隔单位',
            align:"center",
            dataIndex: 'repeatGapUnit_dictText'
          },
          {
            title:'上次保养时间',
            align:"center",
            dataIndex: 'maintenanceLastTime',
            customRender:function (text) {
              return !text?"":(text.length>10?text.substr(0,10):text)
            }
          },
          {
            title:'下次计划保养时间',
            align:"center",
            dataIndex: 'maintenanceNextTime',
            customRender:function (text) {
              return !text?"":(text.length>10?text.substr(0,10):text)
            }
          },
          {
            title:'保养时间段开始',
            align:"center",
            dataIndex: 'maintenanceQuantumstart',
            customRender:function (text) {
              return !text?"":(text.length>10?text.substr(0,10):text)
            }
          },
          {
            title:'保养时间段结束',
            align:"center",
            dataIndex: 'maintenanceQuantumend',
            customRender:function (text) {
              return !text?"":(text.length>10?text.substr(0,10):text)
            }
          },
          {
            title:'保养类型',
            align:"center",
            dataIndex: 'maintenanceType_dictText'
          },
          {
            title:'保养内容',
            align:"center",
            dataIndex: 'maintenanceContext'
          },
          {
            title:'模版ID',
            align:"center",
            dataIndex: 'templateId_dictText'
          },
          {
            title:'化学药剂',
            align:"center",
            dataIndex: 'productId_dictText'
          },
          {
            title:'运维材料',
            align:"center",
            dataIndex: 'materialId_dictText'
          },
          {
            title:'运维状态',
            align:"center",
            dataIndex: 'maintenanceStatus_dictText',
            customRender:function (text) {
              return !text||text==''?"待接单":text
            }
          },
          {
            title: '操作',
            dataIndex: 'action',
            align:"center",
            fixed:"right",
            width:147,
            scopedSlots: { customRender: 'action' }
          }
        ],
        url: {
          list: "/dev/yksEquipmentDevops/list",
          delete: "/dev/yksEquipmentDevops/delete",
          deleteBatch: "/dev/yksEquipmentDevops/deleteBatch",
          exportXlsUrl: "/dev/yksEquipmentDevops/exportXls",
          importExcelUrl: "dev/yksEquipmentDevops/importExcel",
          
        },
        dictOptions:{},
        superFieldList:[],
        currentEquipmentId:'',
        serviceType:''
      }
    },
    created() {
    this.getSuperFieldList();
    },
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      },
    },
    methods: {
      myHandleAdd: function () {
        
      this.$refs.modalForm.currentEquipmentId = this.currentEquipmentId
      this.$refs.modalForm.serviceType = this.serviceType
      this.$refs.modalForm.add()
      this.$refs.modalForm.title = '新增'
      this.$refs.modalForm.disableSubmit = false
    },
    myHandleEdit(record) {
      console.log('项目id:'+record.equipmentId)
        
      this.$refs.modalForm.currentEquipmentId = record.equipmentId
      this.$refs.modalForm.serviceType = this.serviceType
      this.$refs.modalForm.edit(record)
      this.$refs.modalForm.title = '编辑'
      this.$refs.modalForm.disableSubmit = false
    },
      open(record,serviceType) {
        this.currentEquipmentId = record.id
        this.serviceType=serviceType
        this.loadData(1)
      },
      loadData(arg) {
        debugger

        if(!this.url.list){
          this.$message.error("请设置url.list属性!")
          return
        }
        //加载数据 若传入参数1则加载第一页的内容
        if (arg === 1) {
          this.ipagination.current = 1;
        }
        var params = this.getQueryParams();//查询条件
        params.equipmentId = this.currentEquipmentId
        params.devopsPersontype=this.serviceType
        this.loading = true;
        getAction(this.url.list, params).then((res) => {
          if (res.success) {
            //update-begin---author:zhangyafei    Date:20201118  for：适配不分页的数据列表------------
            this.dataSource = res.result.records||res.result;
            if(res.result.total)
            {
              this.ipagination.total = res.result.total;
            }else{
              this.ipagination.total = 0;
            }
            //update-end---author:zhangyafei    Date:20201118  for：适配不分页的数据列表------------
          }else{
            this.$message.warning(res.message)
          }
        }).finally(() => {
          this.loading = false
        })
      },
      initDictConfig(){
      },
      getSuperFieldList(){
        let fieldList=[];
        fieldList.push({type:'string',value:'name',text:'名称',dictCode:''})
        fieldList.push({type:'string',value:'equipmentId',text:'项目',dictCode:"yks_equipment,name,id"})
        fieldList.push({type:'string',value:'devopsPersontype',text:'运维类型',dictCode:'devops_persontype'})
        fieldList.push({type:'string',value:'maintenancePerson',text:'运维人员',dictCode:"sys_user,username,id"})
        fieldList.push({type:'string',value:'maintenanceDept',text:'运维部门',dictCode:"sys_depart,depart_name,id"})
        fieldList.push({type:'string',value:'triggerType',text:'触发类型',dictCode:'trigger_type'})
        fieldList.push({type:'date',value:'triggerTime',text:'初次触发时间'})
        fieldList.push({type:'string',value:'repeatNumber',text:'重复次数',dictCode:''})
        fieldList.push({type:'string',value:'repeatGap',text:'重复间隔',dictCode:''})
        fieldList.push({type:'string',value:'repeatGapUnit',text:'重复间隔单位',dictCode:"yks_unit,name,id"})
        fieldList.push({type:'date',value:'maintenanceLastTime',text:'上次保养时间'})
        fieldList.push({type:'date',value:'maintenanceNextTime',text:'下次机会保养时间'})
        fieldList.push({type:'date',value:'maintenanceQuantumstart',text:'保养时间段开始'})
        fieldList.push({type:'date',value:'maintenanceQuantumend',text:'保养时间段结束'})
        fieldList.push({type:'string',value:'maintenanceType',text:'保养类型',dictCode:'maintenance_type'})
        fieldList.push({type:'string',value:'maintenanceContext',text:'保养内容',dictCode:''})
        fieldList.push({type:'string',value:'templateId',text:'模版ID',dictCode:"yks_maintenance_template,template_name,id"})
        fieldList.push({type:'string',value:'productId',text:'化学药剂',dictCode:"dev_equipment_config_product,product_name,id"})
        fieldList.push({type:'string',value:'materialId',text:'运维材料',dictCode:"yks_equipment_configuration_part,material_name,id"})
        fieldList.push({type:'int',value:'maintenanceStatus',text:'运维状态',dictCode:'maintenance_status'})
        this.superFieldList = fieldList
      },
      //跳转到保养内容维护界面
      // goToMaintenanceTemplateList(){
      //   this.$router.push(YksMaintenanceTemplateListVue)
      // }
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>